<?php
class StatisticsAction extends BaseAction {
	public function index(){

	}

	public function day(){
		//获取一天开始时间和结束时间
		$date = new Date();
		$dayTime = $date->format('%Y-%m-%d');
		$startTime =  strtotime($dayTime);
		$endTime =  strtotime($date->dateAdd(1, 'd')->format('%Y-%m-%d'));
		//进行活动数量统计
		$map['create_time'] = array(array('gt',$startTime),array('lt',$endTime));
		$map['status'] = 100;//必须是完成的状态才会在统计范围只内

		$TaskAllotModel = $this->MTASK('TaskAllot');
		$TaskAuditReturnModel = $this->MTASK('TaskAuditReturn');
		$DesignActivityContModel = $this->MTASK('DesignActivityCont');
		//统计出来有多少人有任务
		$uids = $TaskAllotModel->field('uid, count(1) as count')->where($map)->group('uid')->select();
		if($uids){
			//统计每个维护小图
			foreach($uids as $key=>$uid){
				$myReturnAllCount = 0;
				//获取本人当天任务情况
				$map['uid'] = $uid['uid'];
				$myTasks = $TaskAllotModel->field('uid, tid')->where($map)->select();
				foreach($myTasks as $key2=>$t){
					$m['tid'] = $t['tid'];
					$rCount = $TaskAuditReturnModel->where($m)->group('tid')->count();
					$rCount = intval($rCount);
					$myReturnAllCount += $rCount; 
				}
				//获取每个任务是否有退回信息
				$uids[$key]['return_count'] = $myReturnAllCount;
				$uids[$key]['passing'] = ($uids[$key]['count'] / ($uids[$key]['return_count'] + $uids[$key]['count']));
				//添加数据				
				//获取年
				$data = array();
				$data['year'] = date('Y');
				$data['month'] = date('m');
				$data['day'] = date('d');
				$data = array_merge($data, $uids[$key]);
				$options['table'] = 'm_design_activity_cont_'.$data['year'];
				$DesignActivityContModel->add($data, $options, true);
			}
			
		}
	}

	public function month(){
		//根据日记
		
	}
}